import $ from "jquery";
import {url} from "../../util/config";
import {closeStatus, openStatus} from "../../store/action";
import {message} from "antd";
import {success,error as exception} from '../../util/responseStatus'
import login from "../login";

function getNewLogin(value) {
    return insertLink(value)
}

export default function insertLink(value) {
    let status = null;
    let token = localStorage.getItem("token")
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`LinkManage/InsertLink`,
        type: 'POST',
        contentType:"application/json",
        data:JSON.stringify({
            SORT_NUM:value.sortNum,
            LINK_TYPE:value.type,		    //type: link/small/slideshow
            LINK_NAME:value.name,		    //当type为link时，☑必须有值
            LINK_IMAGE_URL:value.image_url,  //当type为small/slideshow，☑必须有值
            LINK_URL:value.link		        //链接url
            }
        ),
        success: function (result) {
            if(result.result=="Token過期請重新登錄") {
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(value)
            }else {
                if(result.result=="ok"){
                    message.success("新增成功")
                    status = "ok"
                }else message.error("新增失败")
            }
        },
        error:function (error) {
            status = "error";
            message.error("请求异常")
        }
    })
    return status;
    // success();
    // console.log(value)
    // return "ok";
}
